const path = require('path')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
const uglifyJsPlugin = require('uglifyjs-webpack-plugin')

// 配置webpack依赖 node
module.exports = {
  // 入口，要打包的文件
  entry: './src/js/main.js',
  output: {
    // 出口，打包的文件位置
    path: path.join(__dirname, './dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [{
        test: /\.css$/,
        use: ['style-loader', 'css-loader']

        // css-loader只负责加载css,style-loader负责把文件嵌入到文档中
      },
      {
        test: /\.less$/,
        use: [{
          loader: "style-loader" // creates style nodes from JS strings
        }, {
          loader: "css-loader" // translates CSS into CommonJS
        }, {
          loader: "less-loader" // compiles Less to CSS
        }]
      },

      {
        test: /\.(png|jpg|gif)$/,
        use: [{
          loader: 'url-loader',
          // 8kb之下的文件,base格式显示，8kb以上，file-loader加载，
          options: {
            limit: 8192,
            name: 'img/[name].[hash:8].[ext]'
          },
        }]
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['es2015']
          }
        }
      },
      {
        test: /\.vue$/,
        use: ['vue-loader']
      }
    ],

  },
  resolve: {
    alias: {
      'vue$': "vue/dist/vue.esm.js"
    }
  },
  plugins: [new webpack.BannerPlugin('最终版权归崔帆所有'),
    new htmlWebpackPlugin({
      template: 'index.html'
    }),
    new uglifyJsPlugin()
  ],
  devServer: {
    contentBase: './dist',
    inline: true // 页面实时刷新
  }

}